package com.zdy.springbootthymeleaf.controller;

import com.zdy.springbootthymeleaf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;

/**
 * @Author: Deyou
 * @Date: 2021/4/10
 */
@Controller
public class UserController {
    /***
     * 添加用户数据
     * @return
     */
    @GetMapping("/index")
    public String index(Model model){
        ArrayList<User> userList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setId(i);
            user.setName("thymeleaf"+i);
            user.setAge(i);
            userList.add(user);
        }
        model.addAttribute("users",userList);
        model.addAttribute("course","Spring Boot Thymeleaf 课程");
        return "index";
    }
}
